﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ForgeCraftServer.Events;
using System.IO;
using LibMinecraft.Model;

namespace ForgeCraftServer
{
    public class Program
    {
        static StreamWriter Writer;
        static string LogFile;

        static void Main(string[] args)
        {
            // Default settings
            LogFile = "server.log";

            Writer = new StreamWriter(LogFile);
            ForgeCraft.OnLog += new EventHandler<LogEventArgs>(ForgeCraft_OnLog);

            ForgeCraft.Log("ForgeCraft v0.1");

            foreach (string arg in args)
            {
                if (arg.StartsWith("-"))
                {
                    switch (arg.Substring(1))
                    {
                        // Arguments
                        // Format:
                        // ForgeCraft -noparam -param:value
                    }
                }
            }

            ForgeCraft.Log("Loading ForgeCraft...");

            ForgeCraft.Initialize();
            ForgeCraft.LoadSettings(Directory.GetCurrentDirectory());

            ForgeCraft.Log("Starting ForgeCraft server on port " + ForgeCraft.MinecraftServer.Port);

            ForgeCraft.Start();

            ForgeCraft.Log("ForgeCraft started successfully!");

            while (true)
            {
                string input = Console.ReadLine();
            }
        }

        static void ForgeCraft_OnLog(object sender, LogEventArgs e)
        {
            Console.WriteLine(e.Message);
            Writer.WriteLine(e.Message);
            Writer.Flush();
        }
    }
}
